<?php $this->load->view('layout/lottery/header') ?>
<div class="lotteryMain">
	<div class="panel panel-default">
		<div class="panel-heading">中奖用户列表 LIST OF WINNING USERS</div>
		<div class="panel-body">
	  		<form class="form-horizontal form-search" action="<?php echo site_url('lottery/winners') ?>" method="get">
	  			<div class="clearfix form-text">
	  				<div class="form-group clearfix">
					    <label class="control-label">中奖者</label>
					    <input type="text" class="form-control txt" placeholder="请输入中奖者账号" name="user_name" value="<?php echo $this->input->get('user_name'); ?>">
					</div>
	  				<div class="form-group clearfix">
					    <label class="control-label">活动名称</label>
					    <select class="txt" name="lottery_id">
					    	<option value="0">全部</option>
					    	<?php if (isset($lotteryResult)) : ?>
					    	<?php foreach($lotteryResult as $key=>$value) : ?>
					    	<option value="<?php echo $key; ?>" <?php echo ($key == $this->input->get('lottery_id')) ? 'selected="selected"' : ''; ?>><?php echo $value; ?></option>
					    	<?php endforeach; ?>
					    <?php endif; ?>
					    </select>
					</div>
					<div class="form-group clearfix">
					    <label class="control-label">中奖等级</label>
					    <select class="txt" name="grade">
					    	<option value="">全部</option>
					    	<?php foreach(prizeGrade() as $key=>$value) : ?>
							<option value="<?php echo $key; ?>" <?php echo ($key == $this->input->get('grade')) ? 'selected="selected"' : ''; ?>><?php echo $value, '等奖'; ?></option>
							<?php endforeach; ?>
					    </select>
					</div>
					<div class="form-group clearfix time">
					    <label class="control-label">中奖时间</label>
					    <span><input type="text" value="<?php echo $this->input->get('startDate'); ?>" class="form-control txt" placeholder="开始时间" onclick="calendar.show({ id: this })" readonly="readonly" /></span>
					    <span>&nbsp;至&nbsp;</span>
					    <span><input type="text" class="form-control txt" value="<?php echo $this->input->get('endDate'); ?>" placeholder="结束时间" onclick="calendar.show({ id: this })" readonly="readonly" /></span>
					</div>
					<div class="form-group clearfix">
					    <label class="control-label">状态</label>
					    <select class="txt" name="status">
					    	<option value="0">全部</option>
					    	<option value="1" <?php echo (1 == $this->input->get('status')) ? 'selected="selected"' : ''; ?>>
					    		未领奖
					    	</option>
					    	<option value="2" <?php echo (2 == $this->input->get('status')) ? 'selected="selected"' : ''; ?>>
					    		待发奖
					    	</option>
					    	<option value="3" <?php echo (3 == $this->input->get('status')) ? 'selected="selected"' : ''; ?>>
					    		已发货
				    		</option>
					    </select>
					</div>
					<div class="form-group clearfix">
					    <label class="control-label">奖品类型</label>
					    <select class="txt" name="prize_type">
					    	<option value="0">全部</option>
					    	<option value="1" <?php echo (1 == $this->input->get('prize_type')) ? 'selected="selected"' : ''; ?>>
					    		实物
					    	</option>
					    	<option value="2" <?php echo (2 == $this->input->get('prize_type')) ? 'selected="selected"' : ''; ?>>
					    		虚拟物品
				    		</option>
					    	<option value="3" <?php echo (3 == $this->input->get('prize_type')) ? 'selected="selected"' : ''; ?>>
					    		金币
					    	</option>
					    	<option value="4" <?php echo (3 == $this->input->get('prize_type')) ? 'selected="selected"' : ''; ?>>
					    		现场颁奖
					    	</option>
					    </select>
					</div>
					<div class="form-group clearfix">
					    <label class="control-label">推荐人</label>
					    <input type="text" class="form-control txt" placeholder="请输入推荐人账号" name="reseller_name" value="<?php echo $this->input->get('reseller_name'); ?>">
					</div>
				</div>

				<div class="clearfix form-btns">
					<input type="submit" value="搜索" class="btn btn-submit" />
					<a value="" class="btn btn-gray" />重置条件</a>
				</div>
			</form>
		</div>
	</div>

	<div class="lotteryList">
		<?php if ($all_rows > 0) : ?>
		<table class="table table-striped mytable-striped">
			<thead>
				<tr>
					<th width="40">编号</th>
					<th width="80">用户名称</th>
					<th width="120">活动名称</th>
					<th width="65">等级</th>
					<th width="160">奖品名称</th>
					<th width="80">奖品类型</th>
					<th width="140">奖品过期时间</th>
					<th width="140">中奖时间</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<?php foreach ($page_list->result() as $item) : ?>
				<tr>
					<td><?php echo $item->id; ?></td>
					<td><?php echo mb_substr($item->user_name, 0, 1), '***', mb_substr($item->user_name, -1, 1); ?></td>
					<td><?php echo $lotteryResult[$item->lottery_id]; ?></td>
					<td><?php echo prizeGrade()[$item->grade], '等奖'; ?></td>
					<td><?php echo $item->prize_name; ?></td>
					<td><?php 
							switch ($item->prize_type) {
								case 1:
									echo '实物';
									break;
								case 2:
									echo '虚拟物品';
									break;
								case 3:
									echo '金币';
									break;
								case 4:
									echo '现场颁奖';
									break;
								case 4:
									echo '其它';
									break;
								default:
									break;
							}; 
						?></td>
					<td><?php echo $item->effective_date; ?></td>
					<td><?php echo $item->created_at; ?></td>
					<td>
						<div class="op">
							<span class="state">
							<?php switch ($item->status) {
								case 1:
									echo ($item->effective_date < date('Y-m-d H:i:s')) ? '已过期' : '未领奖';
									break;
								case 2:
									echo ($item->effective_date < date('Y-m-d H:i:s')) ? '已过期' : '已领奖';
									break;
								case 3:
									echo '已发货';
									break;
								default:
									break;
							} ?>
							<span class="caret"></span></span>
							<a href="<?php echo site_url('lottery/winnersDetails/'. $item->id); ?>" class="btn">
								<?php echo ($item->status == 2) ? '去发货' : '查看详情'; ?>
							</a>
						</div>
					</td>
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
		<?php $this->load->view('layout/pagination') ?>
		<?php else :?>
            <div class="no-data">
                <img src="skins/images/panda.jpg"/>
                <p>没有搜索到结果</p>
            </div>
        <?php endif;?>
	</div>
</div>
<?php $this->load->view('layout/lottery/footer'); ?>
<?php $this->load->view('layout/lottery/message'); ?>